//
//  ReportListView.m
//  BabyHelper
//
//  Created by  thomas on 11-2-12.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ReportListView.h"

@implementation ReportListView
- (void)viewDidLoad {
	
	self.title = NSLocalizedString(@"Report", @"");
    [super viewDidLoad];

	//set background image
	self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];
	self.view.backgroundColor = [UIColor clearColor];
	//set navigation background color
	self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:navBarRed green:navBarGreen blue:navBarBlue alpha:navBarAlpha];
	
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (NSString *)tableView:(UITableView *)tv titleForHeaderInSection:(NSInteger)section
{
	NSString *title = nil;
	
	switch(section){
		case 0:
			title = NSLocalizedString(@"Baby Activity Report", @"");
			break;
		default:
			break;
	}
	
	return title;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	
	switch (indexPath.row) {
		case 0:
			cell.textLabel.text = NSLocalizedString(@"Last 12 hours", @"");
			break;
		case 1:
			cell.textLabel.text = NSLocalizedString(@"Last 24 hours", @"");
			break;
		case 2:
			cell.textLabel.text = NSLocalizedString(@"Last 5 days", @"");
			break;
		case 3:
			cell.textLabel.text = NSLocalizedString(@"Custom date", @"");
			break;			
		default:
			break;
	}
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
	switch (indexPath.row) {
		case 0:
		{
			DetailReportView *reportViewController = [[DetailReportView alloc] initWithNibName:@"DetailReportView" bundle:nil];
			NSTimeInterval secondsIn12Hours = 12 * 60 * 60;			
			reportViewController.endTime   = [NSDate date];
			reportViewController.startTime = [[NSDate date] addTimeInterval:-secondsIn12Hours]; 
			[self.navigationController pushViewController:reportViewController animated:YES];
			[reportViewController release];
			break;
		}			
		case 1:
		{
			DetailReportView *reportViewController = [[DetailReportView alloc] initWithNibName:@"DetailReportView" bundle:nil];
			NSTimeInterval secondsIn24Hours = 24 * 60 * 60;
			reportViewController.endTime    = [NSDate date];
			reportViewController.startTime  = [[NSDate date] addTimeInterval:-secondsIn24Hours]; 
			[self.navigationController pushViewController:reportViewController animated:YES];
			[reportViewController release];
			break;
		}
		case 2:
		{
			ReportWithChartView *report = [[ReportWithChartView alloc] initWithNibName:@"ReportWithChartView" bundle:nil];
			[self.navigationController pushViewController:report animated:YES];
			[report release];
			break;
		}			
		case 3:
		{
			TimeSpanSettingView *childView = [[TimeSpanSettingView alloc] initWithNibName:@"TimeSpanSettingView" bundle:nil];
			[self.navigationController pushViewController:childView animated:YES];
			[childView release];
			break;
		}			
		default:
			break;
	}
}

- (void)dealloc {
    [super dealloc];
}



@end

